package com.cloud.basic.Advance.Design.Flyweight_Pattern;

import java.util.Random;

/**
 * @program: basic
 * @description: 测试享元模式
 * @author: Cloud
 * @create: 2022/2/23 15:15:57
 */
public class TestFlyweightPatter {

    public static void main(String[] args) {
        ChessmanFactory chessmanFactory = ChessmanFactory.getInstance();
        Random random = new Random();
        int radom = 0;
        AbstractChessman abstractChessman = null;
        for (int i = 0; i < 10; i++) {
            radom = random.nextInt(2);
            switch (radom) {
                //获得黑棋子
                case 0:
                    abstractChessman = chessmanFactory.getChessmanObject('B');
                    break;
                case 1:
                    abstractChessman = chessmanFactory.getChessmanObject('W');
                    break;
            }
            if (abstractChessman != null) {
                abstractChessman.point(i,random.nextInt(15));
            }
        }
    }
}
